package com.szrt.java.day20170112.demo05;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


/**
 * "中深软通1612" 输出到1个文件中 zsrt.txt
 * @author zsrt
 *
 */

public class FileWriteTest {

	public static void main(String[] args) throws IOException {
		/*
		File file = new File("src/com/szrt/java/day20170112/demo05/zsrt.txt");
		
		FileWriter fw = new FileWriter(file);
		
		String target = "中深软通1612";
		
		char[] b = target.toCharArray();
		
		fw.write(b);
        fw.close();	*/	
		
		File rFile = new File("src/com/szrt/java/day20170112/demo05/abc.txt");
		
		File wRile = new File("src/com/szrt/java/day20170112/demo05/cba.txt");
		
		FileReader fr = new FileReader(rFile);
		FileWriter fw = new FileWriter(wRile);
		
		char[] b = new char[5];
		
		String target = ""; 
		
		int len = 0;
		while((len = fr.read(b)) != -1){
			String str = new String(b,0,len);
			target = target+str;
			//System.out.println(str);
			//System.out.print(str);
		}
		
		char[] w = target.toCharArray();
		fw.write(w);
		
		fr.close();
		fw.close();
		
		
	}
		
		
		
	
	public void copyWord() throws IOException{
		
		File rFile = new File("src/com/szrt/java/day20170112/demo05/abc.txt");
		
		File wRile = new File("src/com/szrt/java/day20170112/demo05/cba.txt");
		
		FileReader fr = new FileReader(rFile);
		FileWriter fw = new FileWriter(wRile);
		
		char[] b = new char[5];
		
		String target = ""; 
		
		int len = 0;
		while((len = fr.read(b)) != -1){
			String str = new String(b,0,len);
			target = target+str;
			//System.out.println(str);
			//System.out.print(str);
		}
		
		char[] w = target.toCharArray();
		fw.write(w);
		
		fr.close();
		fw.close();
	}
	
}
